/**
 * TODO: Vložit licenci. 
 */

package cz.enif.commander.values;

import java.util.ArrayList;
import java.util.List;

/**
 * Hodnota typu DOUBLE.
 * 
 * @author enif
 *
 */
final class DoubleValue implements IValue 
{
	//// CONSTRUCTORS ////
	
	/**
	 * Konstruktor.
	 * 
	 * @param value Hodnota, která má být uložena do objektu DoubleValue. 
	 */
	public DoubleValue(double value)
	{
		this.value = value;
	}
	
	//// PUBLIC ////

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getType()
	 */
	@Override
	public ValueType getType() 
	{
		return ValueType.DOUBLE;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isBool()
	 */
	@Override
	public boolean isBoolean() 
	{
		return false;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isInt()
	 */
	@Override
	public boolean isInt() 
	{
		return false;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isDouble()
	 */
	@Override
	public boolean isDouble() 
	{
		return true;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isString()
	 */
	@Override
	public boolean isString() 
	{
		return false;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isTuple()
	 */
	@Override
	public boolean isTuple() 
	{
		return false;
	}
	
	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getBoolValue()
	 */
	@Override
	public boolean getBooleanValue() 
	{
		return this.value != 0.0;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getIntValue()
	 */
	@Override
	public int getIntValue() 
	{
		return (int)this.value;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getDoubleValue()
	 */
	@Override
	public double getDoubleValue() 
	{
		return this.value;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getStringValue()
	 */
	@Override
	public String getStringValue() 
	{
		return Double.toString(this.value);
	}
	
	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getTupleValue()
	 */
	@Override
	public List<IValue> getTupleValue() 
	{
		List<IValue> tuple = new ArrayList<IValue>(1);
		tuple.set(0, ValueFactory.valueOf(this.value));
		
		return tuple;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getLength()
	 */
	@Override
	public int getSize() 
	{
		return 1;
	}
	
	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#toString()
	 */
    @Override
    public String toString()
    {
        return this.getStringValue();
    }
	
	//// PRIVATE ////
	
    /** Uložená hodnota. */
	private final double value;
}
